﻿using Mysoft.Map.Extensions.DAL;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

namespace TestMySqlConnection
{
    public partial class Form1 : Form
    {
        public object CPQueryConn { get; private set; }

        public Form1()
        {
            InitializeComponent();
        }

        private string GetConnstr()
        {
            return string.Format("server={0};User Id={1};password={2};Database={3};CharSet=utf8;port={4}", txtserver.Text,
               txtusername.Text, txtpassword.Text, txtdbname.Text, txtport.Text);
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            try
            {
                using (MySqlConnection conn = new MySqlConnection(GetConnstr()))
                {
                    MySqlCommand com = new MySqlCommand();
                    com.Connection = conn;
                    com.CommandText = "select 1";
                    conn.Open();
                    string result = com.ExecuteScalar().ToString();
                    conn.Close();
                    MessageBox.Show("连接成功："+ result);
                }
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
           
        }
    }
}
